from appium import webdriver
from appium_PO_test.page.base_page import BasePage
from appium_PO_test.page.main_page import MainPage



class App(BasePage):
    def start(self):
        if self.driver == None:
            print("self.driver == None,初始化driver")
            #启动APP
            caps = {}
            caps["platformName"] = "android"
            caps["appPackage"] = "com.tencent.wework"
            caps["appActivity"] = ".launch.LaunchSplashActivity"
            caps["deviceName"] = "127.0.0.1:7555"
            caps["noReset"] = "true"
            caps["settings[waitForIdleTimeout]"] = 0
            caps["noReset"]="true"
            caps["skipDeviceInitialization"]=True
            self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
            self.driver.implicitly_wait(30)
        else:
            print("复用driver")
            self.driver.launch_app()
        return self

    def restart(self):
        self.driver.close()
        self.driver.launch_app()

    def stop(self):
        self.driver.quit()

    def goto_main(self):
        #入口
        return MainPage(self.driver)